package cn.zyjblogs.controller;

import cn.zyjblogs.entity.Customer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
public class SearchController {

    @Value("${server.port}")
    private String port;

    @GetMapping("/search")
    public String search() {
//        int i = 1/0;
        return "search:" + port;
    }

    @GetMapping("/search/{id}")
    public Customer findById(@PathVariable Integer id) {
        return new Customer(1, "zhangsan", (int) (Math.random() * 100000));
    }

    @GetMapping("/getCustomer")
    public Customer getcustomer(@RequestParam Integer id, @RequestParam String name) {
        return new Customer(id, name, (int) (Math.random() * 100000));
    }

    @PostMapping("save")
    public Customer save(@RequestBody Customer customer) {
        return customer;
    }
}
